//
//  BaseTableViewController.swift
//  0110-weibo
//
//  Created by 鲍志刚 on 16/1/10.
//  Copyright © 2016年 zhongye. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VisitorLoginViewDelegate {

    // 定义用户是否登录的提示
    var userLogin = UserAccountViewModel().userLogin
    
    //访客试图
    var visitorLoginView: VisitorLoginView?
    
    
    //loadView
    //1.苹果专门为 手写代码准备的 一旦实现改方法 sb / xib 会自动失效
    //2.准备仕途层次结构 在UIViewController 中 会将view 准备出来
    //3.在super.loadView之前 view没有被创建出来(nil) 追踪view 会造成递归调用
    override func loadView() {
        if  userLogin {
        //创建tableview
        super.loadView()
//            print(view)
        } else {
        
        // 自定义访客试图
          visitorLoginView = VisitorLoginView()
            view = visitorLoginView
            
            visitorLoginView?.visitorLoginViewDelegate = self
 
        }
    }
    
    
     //MARK: 实现 VisitorLoginViewDelegate 协议方法
    func userWillRegister() {
        print(__FUNCTION__)
    }
    
    
    func userWillLogin() {
        print(__FUNCTION__)
        
        let oauth = OAuthViewController()
        
        let nav = UINavigationController(rootViewController: oauth)
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
